<?php

namespace App\Modules\LuckDraw\Services;

use App\Http\Model\FinanceDiamond;
use App\Http\Model\FinanceUserWallet;
use App\Http\Model\Hint;
use App\Http\Model\Prop;
use App\Http\Services\CommonRoomMsgServices;
use App\Http\Services\FinanceWalletServices;
use App\Http\Services\MsgServices;
use App\Http\Services\UserServices;
use App\Modules\LuckDraw\Award\AwardFactory;
use App\Modules\LuckDraw\LuckDraw\LuckDrawFactory;
use App\Modules\LuckDraw\LuckDraw\LuckDrawInterface;

use Illuminate\Support\Facades\DB;

class LuckDrawService {
    private $_luckDrawInstance;
    public function  __construct (?LuckDrawInterface $luckDraw = null) {
        $this->_luckDrawInstance = $luckDraw;
    }

    //执行抽奖
    public function run($num) : ?array {
       return $this->_luckDrawInstance->run($num);
    }

    //兑换道具
    public function exchange(int $num) : array {
        return $this->_luckDrawInstance->exchange($num);
    }

    //活动赠送
    public function present(int $num) : array {
        return $this->_luckDrawInstance->present($num);
    }

    //获取用户资产
    public function banlance(){
        return $this->_luckDrawInstance->banlance();
    }

    //获取规则
    public function rule() {
        return $this->_luckDrawInstance->rule();
    }


    //中奖记录
    public function record(int $page_num, int $page_size): array {
        return $this->_luckDrawInstance->record($page_num, $page_size);
    }
    //排行榜
    public function ranking(int $top){
        return $this->_luckDrawInstance->ranking($top);
    }

    public function price(){
        return $this->_luckDrawInstance->getPrice();
    }

    public function isLocked(array $luckIds): ?array {
        $lockedArr = [];
        foreach ($luckIds as $luckId) {
            $luckDraw = LuckDrawFactory::get($luckId);
            if ($luckDraw == null) {
                return null;
            }
            $start = $luckDraw->isStart();
            //没有开始
            if (!$start) {
                $lockedArr[] =[
                    'luckId' => $luckId,
                    'locked' => true,
                    'expNeed' => $luckDraw->getExpNeed(),
                    'expAdd' => $luckDraw->getExpAdd(),
                    'start' => $luckDraw->getStart(),
                    'end' => $luckDraw->getEnd()
                ];
                continue;
            }
            //已经开始
            $lockedArr[] = [
                'luckId' => $luckId,
                'locked' => false,
                'expNeed' => $luckDraw->getExpNeed(),
                'expAdd' => $luckDraw->getExpAdd(),
                'start' => $luckDraw->getStart(),
                'end' => $luckDraw->getEnd()
            ];
        }
        return $lockedArr;
    }

    //走马灯
    public function marquee(int $top){
        return $this->_luckDrawInstance->marquee($top);
    }

    public function awardList (){
        return $this->_luckDrawInstance->awardList();
    }
}